package com.example.test;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		findViewById(R.id.homeAsUp).setOnClickListener(clickListener);
		findViewById(R.id.showHome).setOnClickListener(clickListener);
		findViewById(R.id.useLogo).setOnClickListener(clickListener);
		findViewById(R.id.showTitle).setOnClickListener(clickListener);
		
		View myView = getLayoutInflater().inflate(R.layout.action_button, null);
		
		myView.findViewById(R.id.button1).setOnClickListener(clickListener);
		myView.findViewById(R.id.button2).setOnClickListener(clickListener);
		myView.findViewById(R.id.button3).setOnClickListener(clickListener);
		
		ActionBar ab = getActionBar();
		ab.setCustomView(myView);
		ab.setDisplayShowCustomEnabled(true);
	}

	OnClickListener clickListener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch(v.getId()){
			case R.id.homeAsUp:
				getActionBar().setDisplayOptions(
						ActionBar.DISPLAY_HOME_AS_UP|ActionBar.DISPLAY_SHOW_HOME);
				break;
			case R.id.showHome:
				getActionBar().setDisplayOptions(
						ActionBar.DISPLAY_SHOW_HOME);
				break;
			case R.id.useLogo:
				getActionBar().setDisplayOptions(
						ActionBar.DISPLAY_USE_LOGO|ActionBar.DISPLAY_SHOW_HOME);
				break;
			case R.id.showTitle:
				getActionBar().setDisplayOptions(
						ActionBar.DISPLAY_SHOW_TITLE);
				break;
				default:
					Toast.makeText(MainActivity.this, 
							((Button)v).getText() + "...", Toast.LENGTH_SHORT).show();
					break;
			}
		}
	};
//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.main, menu);
//		return true;
//	}
//
//	@Override
//	public boolean onOptionsItemSelected(MenuItem item) {
//		// Handle action bar item clicks here. The action bar will
//		// automatically handle clicks on the Home/Up button, so long
//		// as you specify a parent activity in AndroidManifest.xml.
//		int id = item.getItemId();
//		switch(id){
//		case android.R.id.home:
//			Toast.makeText(this, "Home.....", Toast.LENGTH_SHORT).show();
//			//actionBar.hide();
//			break;
//		case R.id.menu_refresh:
//			Toast.makeText(this, "Refresh...", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.menu_search:
//			Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.menu_share:
//			Toast.makeText(this, "Share...", Toast.LENGTH_SHORT).show();
//			break;
//		}
//		return super.onOptionsItemSelected(item);
//	}

}
